#include <iostream>
#include <vector>
#include <iomanip>
#include "Function.hpp" 
#include "Spline.hpp" 

// Define the function f(x) = 1 / (1 + 25 * x^2)
double f(double x) {
    return 1.0 / (1.0 + 25 * x * x);
}

int main() {
    // 定义节点和对应的函数值
    int n=10;
    std::vector<double> x(11);  // 节点
    std::vector<double> y(11);  // 函数值
    for (int i=0;i<=n;++i){
        x[i] = -5+10/n*i;
        y[i] = f(-5+10/n*i);
    }
    // Create a LinearPPForm object
    BSpline spline1(x, y,3,"natural");

    // Test points for interpolation
    std::vector<double> test_points = {0.5, 1.5, 2.5, 3.5};
    std::cout << "Test3(BSpline):" << std::endl;
    // Output the spline values at test points
    std::cout << "Uniform node natural BSpline Spline Interpolation Test Results:" << std::endl;
    for (double x : test_points) {
        double value = spline1.getSplineValue(x);
        std::cout << "Spline value at x = " << x << " : " << value << std::endl;
    }

    BSpline spline2(x, y,3,"complete",25/26.0/26.0,-25/26.0/26.0);
    std::cout << "Uniform node complete BSpline Spline Interpolation Test Results:" << std::endl;
    for (double x : test_points) {
        double value = spline1.getSplineValue(x);
        std::cout << "Spline value at x = " << x << " : " << value << std::endl;
    }

    BSpline spline3(x, y,3,"periodic");
    std::cout << "Uniform node periodic BSpline Spline Interpolation Test Results:" << std::endl;
    for (double x : test_points) {
        double value = spline3.getSplineValue(x);
        std::cout << "Spline value at x = " << x << " : " << value << std::endl;
    }

    x[1]=-4.5;
    y[1]=f(-4.5);
    x[9]=4.5;
    y[9]=f(4.5);
    // Create a LinearPPForm object
    BSpline spline4(x, y,3,"natural");

    // Output the spline values at test points
    std::cout << "Non-uniform node natural BSpline Spline Interpolation Test Results:" << std::endl;
    for (double x : test_points) {
        double value = spline4.getSplineValue(x);
        std::cout << "Spline value at x = " << x << " : " << value << std::endl;
    }

    BSpline spline5(x, y,3,"complete",25/26.0/26.0,-25/26.0/26.0);
    std::cout << "Non-uniform node complete BSpline Spline Interpolation Test Results:" << std::endl;
    for (double x : test_points) {
        double value = spline5.getSplineValue(x);
        std::cout << "Spline value at x = " << x << " : " << value << std::endl;
    }

    BSpline spline6(x, y,3,"periodic");
    std::cout << "Non-uniform node periodic BSpline Spline Interpolation Test Results:" << std::endl;
    for (double x : test_points) {
        double value = spline6.getSplineValue(x);
        std::cout << "Spline value at x = " << x << " : " << value << std::endl;
    }
    return 0;
}